/*
 *  QMMatch.cpp
 *  QuickMatch
 *
 *  Created by Leroy Ketelaars on 8/13/09.
 *  Copyright 2009 Universum7. All rights reserved.
 *
 */

#include "QMMatch.h"
#include "SDL.h"
#include "HitTest.h"

bool QMMatch::handleInteraction()
{
	while(SDL_PollEvent(events))
	{
		switch(events->type)
		{
			case SDL_MOUSEMOTION:
			//	printf(" -> MouseMotion Event\n");
				mx = events->motion.x;
				my = events->motion.y;				
			break;
			case SDL_MOUSEBUTTONDOWN:
			//	printf(" -> MouseButton Event\n");
			
				if(!HitTest(mx, my, widget.bounds))
				{
					if(events->button.button == SDL_BUTTON_LEFT)
					{
						this->forkbase->delegate = forkbase;
					}
				}
				else
				{
					#warning "QMMatch dragging is still being implemented"
					/*
					int xoffs = mx - bounds.x;
					int yoffs = my - bounds.y;
					int x = bounds.x - xoffs;
					int y = bounds.y - yoffs;
					this->setBounds(x, y);
					*/
				}
					
			break;
			case SDL_MOUSEBUTTONUP:
				
			break;
			case SDL_KEYUP:
		//	printf(" -> KeyDown Event\n");
			
				switch(events->key.keysym.sym)
				{
					case SDLK_SPACE:
						
					break;
					case SDLK_RETURN:
						
					break;
					case SDLK_ESCAPE:

					break;
					default: break;
				}
			break;
			case SDL_QUIT:
			printf(" -> Quit Event from QMMatch\n");
				this->forkbase->delegate = forkbase;
				this->forkbase->delegate->run = false;
				this->run = false;		
				//return false;
			break;
			default:
			break;
		}
	}
	return true;
}

QMMatch::QMMatch()
{
	mousedragflag = false;
	printf("A QMMatch Object was created @ %p\n", this);
}
QMMatch::~QMMatch()
{
	if(vs_seperator != NULL)
	{
		SDL_FreeSurface(vs_seperator);
		vs_seperator = NULL;
	}
	printf("A QMMatch Object was deleted @ %p\n", this);
	
}

